{% load static %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的数据</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { margin: 0; padding: 0; }
        .sidebar {
            width: 250px;
            height: 100vh;
            background-color: #343a40;
            color: white;
            position: fixed;
            padding: 20px;
        }
        .sidebar img {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            object-fit: cover;
            margin-bottom: 10px;
        }
        .content {
            margin-left: 260px;
            padding: 40px;
        }
        .btn-custom {
            width: 100%;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>

<div class="sidebar text-center">
    <img src="{% static 'images/img.png' %}" alt="头像">
    <h5 class="mt-2">{{ request.user.username }}</h5>
    <hr class="bg-light">
    <a href="{% url 'home' %}" class="btn btn-outline-light btn-custom">主页</a>
    <a href="{% url 'data_list' %}" class="btn btn-outline-light btn-custom">我的数据</a>
    <a href="{% url 'data_add' %}" class="btn btn-outline-light btn-custom">添加新数据</a>
    <a href="{% url 'import_json' %}" class="btn btn-outline-light btn-custom">导入 JSON</a>
    <a href="{% url 'export_json' %}" class="btn btn-outline-light btn-custom">导出 JSON</a>
    <a href="{% url 'logout' %}" class="btn btn-danger btn-custom">退出登录</a>
</div>

<div class="content">
    <h3 class="mb-4">我的数据</h3>

    <form method="get" class="mb-3 d-flex" style="max-width: 400px; height: 36px;">
    <input type="text" name="q" class="form-control me-2" placeholder="按标题搜索" value="{{ request.GET.q }}" style="height: 100%;">
    <button type="submit" class="btn btn-outline-primary" style="height: 100%; padding: 0 12px; line-height: 1.5;">搜索</button>
</form>

    <table class="table table-striped">
        <thead>
            <tr>
                <th>标题</th>
                <th>内容</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {% for item in data %}
            <tr>
                <td>{{ item.title }}</td>
                <td>{{ item.content }}</td>
                <td>
                    <a href="{% url 'data_edit' item.id %}" class="btn btn-sm btn-warning">编辑</a>
                    <a href="{% url 'data_delete' item.id %}" class="btn btn-sm btn-danger" onclick="return confirm('确定删除？');">删除</a>
                </td>
            </tr>
            {% empty %}
            <tr><td colspan="3">暂无数据</td></tr>
            {% endfor %}
        </tbody>
    </table>
</div>

</body>
</html>

